# -*- coding=utf-8 -*-
from DllReader import USBCANDllReader
import datetime, time
from CanFrame import CanFrame

can_id_tx = 0x7FF
can_id_rx = 0x7FE

cmd_list = [
    {"ID":1, "title": "进入工厂自动化测试模式", "data": [0x55, 0xaa, 0x5a, 0x5a, 0xa5, 0xa5,  0xaa, 0x55]},

    {"ID":10, "title": "获取软件版本", "data": [0x71, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},

    {"ID":4, "title": "测试黑屏", "data": [0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":5, "title": "测试白屏", "data": [0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":6, "title": "测试红屏", "data": [0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":7, "title": "测试绿屏", "data": [0x03, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":8, "title": "测试蓝屏", "data": [0x03, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":9, "title": "测试彩条", "data": [0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":3, "title": "关闭颜色测试", "data": [0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},

    {"ID":11, "title": "调整摄像头视角..视角等级1", "data": [0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":11, "title": "调整摄像头视角..视角等级2", "data": [0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":12, "title": "调整摄像头视角..视角等级3", "data": [0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":12, "title": "调整视频放大比例..放大1.0倍", "data": [0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":12, "title": "调整视频放大比例..放大1.2倍", "data": [0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":12, "title": "调整视频放大比例..放大1.4倍", "data": [0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":13, "title": "设置背光亮度..亮度等级1", "data": [0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":13, "title": "设置背光亮度..亮度等级5", "data": [0x07, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},
    {"ID":13, "title": "设置背光亮度..亮度等级10", "data": [0x07, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},

    {"ID":14, "title": "恢复出厂设置", "data": [0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]},

    {"ID":2, "title": "关闭工厂自动化测试模式", "data": [0xcc, 0x66, 0x66, 0xcc, 0xcc, 0x66, 0x66, 0xcc]}
]

class FactoryTest(object):

    def __init__(self):
        print("FactoryTest init")
        self.cmd_dict = cmd_list
        self.usb_can = USBCANDllReader()

        pass

    def test(self):
        print("开始测试..")
        self.usb_can.openDevice()
        for cmd in cmd_list:
            print(cmd["title"])
            can_frame = CanFrame(can_id_tx, 8, cmd["data"])
            time.sleep(1)
            cmd_text = cmd["title"]
            self.usb_can.transmit(cmd_text, can_frame)

        time.sleep(1)
        self.usb_can.receive()
        self.usb_can.closeDevice()

        input("请输入回车键结束")

        return -1

factory_test = FactoryTest()
factory_test.test()